const { db, sqlExec } = require('../db/mysql57');

const questionDao = {
    /*
     * 获取公共课题库组
     */
    async getgonggongkeQuestionGroup() {
        let sql = `select
                subject as name,
                count(1) as _count,
                '' as img
            from Question
            where type = '公共课'
            group by subject`;
        let data = [];
        return sqlExec(sql, data);
    },
    /*
     * 获取专业课题库组
     */
    async getzhuanyekeQuestionGroup() {
        let sql = `select
                subject as name,
                count(1) as _count
            from Question
            where type = '专业课'
            group by subject`;
        let data = [];
        return sqlExec(sql, data);
    },
    async getQuestionByGonggongke(gonggongke) {
        let sql = `select
                id, title, type,
                subject, pageNum
            from Question
            where subject = ?`;
        let data = [ gonggongke ];
        return sqlExec(sql, data);
    },
    async getQuestionContent(qid) {
        let sql = `select
                title, pageNum
            from Question
            WHERE id = ?`;
        let data = [ qid ];
        return sqlExec(sql, data);
    },
    async getAllQuestion(page) {
        let sql = `select
                id, title, type, subject
            from Question
            LIMIT ?, 50`;
        let data = [ (page-1) * 50 ];
        return sqlExec(sql, data);
    }
};

module.exports = questionDao;
